exports.search_detail = (req, res) => {

  var resultData = {};

  var restfulParams = req.routeInfo.restfulParams;

  //查询审批流程列表
  function searchFlowApproval(cb) {

    R.SEND_HTTP(
      req,
      res,
      {
        url: CORE_APIConfig.coreAPI.flowApprovalSearchInfo.Request_Api_Url + "/ofa_id/" + restfulParams.ofa_id,
        method: 'POST',
        data: {

        }
      },
      function (data) {

        resultData.nodeData = data.result.data[0];

        cb();

      }
    )

  }

  //查询流程中的子节点信息
  function searchFlowApprovalSonNode(cb) {

    //获取子节点信息
    var sonNodeIds = resultData.nodeData.ofa_son_osid.split("|").join(",");

    //根据节点ID查询节点信息
    R.SEND_HTTP(
      req,
      res,
      {
        url: CORE_APIConfig.coreAPI.organizationalStructureSearch.Request_Api_Url + "/in/os_id-" + sonNodeIds + "/sort_order/field(os_id," + sonNodeIds + ") asc",
        method: 'GET'
      },
      function (data) {

        resultData.sonNodeData = data.result.data;

        cb();

      }
    )

  }

  //查询子节点中的用户
  function searchNodeUserData(cb) {

    F.SerialEach(resultData.sonNodeData,function(item,index,callback){

      R.SEND_HTTP(
        req,
        res,
        {
          url: CORE_APIConfig.coreAPI.flowApprovalMiddleSearchInfo.Request_Api_Url + "/ofam_osid/" + item.os_id + "/ofam_ofaid/" + restfulParams.ofa_id + "/ofam_is_delete/0",
          method: 'POST',
          data : {
            fields : [
              "u_id"
            ].join(",")
          }
        },
        function (data) {

          var userIdArr = [];

          //仅保存用户ID
          for(var i=0;i<data.result.data.length;i++){
            userIdArr.push(data.result.data[i].u_id);
          }
  
          item.userData = userIdArr;
  
          callback();
  
        }

      )

    },cb)

  }

  F.Serial([searchFlowApproval, searchFlowApprovalSonNode,searchNodeUserData], () => {

    //将最终结果返回给客户端
    RES.successResponse(res, resultData);

  })

}